package hn.sigit.view;

import java.util.List;

import hn.sigit.model.hnd.cadastre.HND_Parcel;
import hn.sigit.model.hnd.cadastre.dao.HND_ParcelDAO;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;


@Name("parcelQueryHelper")
@Scope(value=ScopeType.CONVERSATION)
@AutoCreate
public class ParcelQueryHelper {
	private String fieldTab;
	private String cadastralKey;
	private String municipalKey;
	
	private String searchSelector = "0";
	
	private List<HND_Parcel> queryResultList;
	private HND_Parcel selectedHndParcel;
	
	
	public String getFieldTab() {
		return fieldTab;
	}
	public void setFieldTab(String fieldTab) {
		this.fieldTab = fieldTab;
	}
	public String getCadastralKey() {
		return cadastralKey;
	}
	public void setCadastralKey(String cadastralKey) {
		this.cadastralKey = cadastralKey;
	}
	public String getMunicipalKey() {
		return municipalKey;
	}
	public void setMunicipalKey(String municipalKey) {
		this.municipalKey = municipalKey;
	}
	
	public String getSearchSelector() {
		return searchSelector;
	}
	public void setSearchSelector(String searchSelector) {
		this.searchSelector = searchSelector;
	}
	
	public List<HND_Parcel> getQueryResultList() {
		if (queryResultList == null) {
			if (searchSelector.equals("1")) {
				queryResultList = HND_ParcelDAO.loadParcelsByCadastralKey(cadastralKey);
			}
			else if (searchSelector.equals("2")) {
				queryResultList = HND_ParcelDAO.loadParcelsByMunicipalKey(municipalKey);
			}
			else {
				queryResultList = HND_ParcelDAO.loadParcelsByFieldTab(fieldTab);
			}
		}
		return queryResultList;
	}
	public void setQueryResultList(List<HND_Parcel> queryResultList) {
		this.queryResultList = queryResultList;
	}
	
	public HND_Parcel getSelectedHndParcel() {
		if (selectedHndParcel == null) {
			if (getQueryResultList().size() > 0)
				selectedHndParcel = getQueryResultList().get(0);
		}
		return selectedHndParcel;
	}
	
	public String doNewSearch() {
		queryResultList = null;
		selectedHndParcel = null;
		
		return null;
	}

	
	
}
